#!/usr/bin/python
# coding:utf-8
__author__ = 'good'
__createday__ = '2015-01-15'

import golsee
from golsee.Helpers import blog_render
from flask import flash, redirect, request, url_for


@golsee.golsee.errorhandler(404)
def not_found_error(error):
    flash(u'你跑错页面了~~~~~')
    print error
    if 'Referer' in request.headers.keys():
        return redirect(request.headers['Referer'])
    else:
        return redirect(url_for('main.index'))


@golsee.golsee.errorhandler(403)
def not_found_error(error):
    flash(u'无权操作')
    return redirect(request.headers['Referer'])


@golsee.csrf.error_handler
def csrf_error(reason):
    return blog_render('error/csrf_error.html', reason=reason), 400


@golsee.golsee.errorhandler(500)
def internal_error(error):
    golsee.db.session.rollback()
    return blog_render('error/500.html'), 500